package com.zh.login.controller;

import cn.hutool.core.date.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Description:
 * @ClassName TestDate
 * @date: 2021.04.07 11:44
 * @Author: zhanghang
 */
public class TestDate {

    public static void main(String[] args) {
        System.out.println(CustomMadeDateUtil.getNextMonthEndDate());
        System.out.println(CustomMadeDateUtil.getNextMonthStartDate());
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.add(Calendar.MONTH, -1);
        calendar.set(Calendar.DAY_OF_MONTH, 0);

        System.out.println(calendar.getTime());

        // 获取当月第一天和最后一天
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String firstday, lastday;
        Calendar cale = Calendar.getInstance();

        // 获取前月的第一天
        cale = Calendar.getInstance();
        cale.add(Calendar.MONTH, 0);
        cale.set(Calendar.DAY_OF_MONTH, 1);
        firstday = format.format(cale.getTime());
        // 获取前月的最后一天
        cale = Calendar.getInstance();
        cale.add(Calendar.MONTH, 1);
        cale.set(Calendar.DAY_OF_MONTH, 0);
        lastday = format.format(cale.getTime());
        System.out.println("本月第一天和最后一天分别是 ： " + firstday + " and " + lastday);

        Calendar cal = Calendar.getInstance();
        cal.setTime(cale.getTime());
        cal.add(Calendar.MONTH, 1);
        System.out.println( DateUtil.formatDate(cal.getTime()));

        Date date=new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(df.format(date));

        calendar.setTime(date);
        calendar.add(Calendar.MONTH, 2);
        calendar.set(Calendar.DATE, 0);

        System.out.println(df.format(calendar.getTime()));

    }
}
